package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import domain.Direccion;
import domain.Este;
import domain.Norte;
import domain.Oeste;
import domain.Sur;

public class CambiarDireccion implements ActionListener{
	private String direccion;
	private int idTeam, idAuto;
	private VentanaJuego vnt;
	
	public CambiarDireccion(VentanaJuego vnt) {
		this.vnt = vnt;
		

	}
	
	private Direccion establecerDireccion(String dir){
		if(dir.equalsIgnoreCase("Norte")){
			return new Norte();
		}
		if(dir.equalsIgnoreCase("Sur")){
			return new Sur();
		}
		if(dir.equalsIgnoreCase("Este")){
			return new Este();
		}
		if(dir.equalsIgnoreCase("Oeste")){
			return new Oeste();
		}
		return null;
	}

	public void actionPerformed(ActionEvent e) {
		this.idTeam = Integer.parseInt(vnt.getIdTeam().getText());
		this.idAuto = Integer.parseInt(vnt.getIdAuto().getText());
		this.direccion = vnt.getDireccion().getText();
		
		Direccion dir = this.establecerDireccion(direccion);
		this.vnt.getPista().cambiarDir(idAuto, idTeam, dir);
	}
}
